package com.hmall.delay.config;

import com.hmall.delay.RedisMQ;
import com.hmall.delay.model.Route;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MqConfig {

    @Value("${mq.monitor.count}")
    private int monitorCount;

    @Value("${mq.queue.payment}")
    private String queuePayment;

    @Value("${mq.consumer.payment}")
    private String listPayment;

//    @Value("${mq.queue.second}")
//    private String queueSecond;
//
//
//    @Value("${mq.consumer.second}")
//    private String listSecond;

    @Bean(name = "redisMQ")
    @Primary
    public RedisMQ getRedisMq() {
        RedisMQ redisMQ = new RedisMQ();
        // 配置监听队列元素数量
        redisMQ.setMonitorCount(monitorCount);
        // 配置路由表
        redisMQ.setRoutes(routeList());
        return redisMQ;
    }

    /**
     * 返回路由表
     * @return
     */
    public List<Route> routeList() {
        List<Route> routeList = new ArrayList<>();
        Route routePayment = new Route(queuePayment, listPayment);
      //  Route routeSecond = new Route(queueSecond, listSecond);
        routeList.add(routePayment);
//        routeList.add(routeSecond);
        return routeList;
    }


}
